﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Globalization;

namespace WebsiteAdmin.Wilson.ProInfo
{
    public partial class ProEdit : System.Web.UI.Page
    {
        public int pkid;
        public string proName;
        public string keywords;
        public string summary;
        public string description;
        public string proCode;
        public string mainImgURL;
        public string bigImgURL;
        public string mediumImgURL;
        public int catID;
        public int catValid;
        public string catName;
        public int serID;
        public int serValid;
        public string serName;
        public string proContent;
        public int sortBy;
        public string packInfo;
        public string proTypeNum;
        public int proReNum = 0;
        public string startDate;
        public string endDate;

        public DataTable dtRtn = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pkid = Convert.ToInt32(Request["pkid"], CultureInfo.InvariantCulture);
                GetProRecommendDate(Global.ConnWilson, pkid);
                DataTable dtPro = Bll.Product.Single(Global.ConnWilson, pkid);
                if (dtPro.Rows.Count == 1)
                {
                    proName = dtPro.Rows[0]["ProName"].ToString();
                    keywords = dtPro.Rows[0]["Keywords"].ToString();
                    summary = dtPro.Rows[0]["Summary"].ToString();
                    description = dtPro.Rows[0]["Description"].ToString();
                    proCode = dtPro.Rows[0]["ProCode"].ToString();
                    mainImgURL = dtPro.Rows[0]["MainImgURL"].ToString();
                    bigImgURL = dtPro.Rows[0]["BigImgURL"].ToString();
                    mediumImgURL = dtPro.Rows[0]["MediumImgURL"].ToString();
                    catID = Convert.ToInt16(dtPro.Rows[0]["CatID"]);
                    catValid = Convert.ToInt16(dtPro.Rows[0]["CatValid"]);
                    catName = dtPro.Rows[0]["CatName"].ToString();
                    serID = Convert.ToInt16(dtPro.Rows[0]["SerID"]);
                    serValid = Convert.ToInt16(dtPro.Rows[0]["SerValid"]);
                    serName = dtPro.Rows[0]["SerName"].ToString();
                    sortBy = Convert.ToInt16(dtPro.Rows[0]["SortBy"]);
                    proContent = dtPro.Rows[0]["ProContent"].ToString();
                    packInfo = dtPro.Rows[0]["PackInfo"].ToString();
                    proTypeNum = dtPro.Rows[0]["ProTypeNum"].ToString();
                    BindCatList();
                }
                dtPro.Dispose();
            }
        }

        protected void BindCatList()
        {
            using (DataTable dt = Bll.Category.MULTIPLE(Global.ConnWilson))
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    this.repCatList.DataSource = dt.DefaultView;
                    this.repCatList.DataBind();
                }
            }
        }

        protected void GetProRecommendDate(string strCon, int proId)
        {
            using (DataTable dt = Bll.RecommendPro.Single(strCon, proId))
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    proReNum = 1;
                    startDate = Convert.ToDateTime(dt.Rows[0]["StarTime"]).ToString("yyyy-MM-dd");
                    endDate = Convert.ToDateTime(dt.Rows[0]["EndTime"]).ToString("yyyy-MM-dd");
                }
            }
        }
    }
}
